Exists
An Exists command is a request to determine whether the object specified by a reference exists. The Finder version of the Exists command is identical to the standard version described in the AppleScript Language Guide.SYNTAX
exists referenceToObject referenceToObject existsPARAMETER
- referenceToObject
- A reference to the object to find or a list of references.
Class: Reference or list of referencesRESULT
A Boolean value. Iftrue
, all of the objects referred to by referenceToObject exist. Iffalse
, one or more of the objects referred to by referenceToObject do not exist.EXAMPLE
This script checks whether a disk named Storage is mounted and, if it is, copies all files from the folder Correspondence whose modification dates are more than 30 days old to disk Storage and deletes the originals.
tell application "Finder" if exists disk "Storage" then set aMonthAgo to (current date) - (30 * days) copy (every item in folder "Correspondence" of startup disk ¬ whose modification date < aMonthAgo) ¬ to folder "Old Letters" of disk "Storage" delete (every item in folder "Correspondence" of startup disk ¬ whose modification date < aMonthAgo) else display dialog "The Storage cartridge isn't mounted." end if end tellNote that you can't use the Move command instead of the Copy and Delete commands in this script, because the Move command changes to Copy when moving items between volumes.